﻿using System.Windows;

using ActiproContrib.Composite.Presentation.Regions;

using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.UnityExtensions;
using Microsoft.Practices.Composite.Presentation.Regions;
using Microsoft.Practices.Unity;

using Supremacy.Resources;
using Supremacy.VFS;

using SupremacyEditor.Services;

namespace SupremacyEditor
{
    internal class Bootstrapper : UnityBootstrapper
    {
        protected override IModuleCatalog GetModuleCatalog()
        {
            return new ConfigurationModuleCatalog();
        }

        protected override void ConfigureContainer()
        {
            Container.RegisterType<ITextService, TextService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IShellView, Shell>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IVFSService, VFSService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IPathDiscoveryService, PathDiscoveryService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IResourceManagerService, ResourceManagerService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IGameDataModel, GameDataModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IEditorController, EditorController>(new ContainerControlledLifetimeManager());

            base.ConfigureContainer();
        }

        protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
            var regionAdapterMappings = base.ConfigureRegionAdapterMappings();
            regionAdapterMappings.RegisterMapping(typeof(ActiproSoftware.Windows.Controls.Docking.DockSite), this.Container.Resolve<DockSiteRegionAdapter>());
            regionAdapterMappings.RegisterMapping(typeof(ActiproSoftware.Windows.Controls.Ribbon.Controls.Primitives.ItemsControlBase), this.Container.Resolve<ItemsControlBaseRegionAdapter>());
            regionAdapterMappings.RegisterMapping(typeof(ActiproSoftware.Windows.Controls.Ribbon.Ribbon), this.Container.Resolve<RibbonRegionAdapter>());
            regionAdapterMappings.RegisterMapping(typeof(ActiproSoftware.Windows.Controls.Ribbon.Controls.Tab), this.Container.Resolve<RibbonTabRegionAdapter>());
            regionAdapterMappings.RegisterMapping(typeof(ActiproSoftware.Windows.Controls.Ribbon.Controls.ContextualTabGroup), this.Container.Resolve<ContextualTabGroupRegionAdapter>());
            regionAdapterMappings.RegisterMapping(typeof(ActiproSoftware.Windows.Controls.Ribbon.Controls.ApplicationMenu), this.Container.Resolve<ApplicationMenuRegionAdapter>());
            return regionAdapterMappings;
        }

        protected override DependencyObject CreateShell()
        {
            var presenter = Container.Resolve<ShellPresenter>();
            var view = presenter.View;
            view.ShowView();

            return view as DependencyObject;
        }
    }
}
